import allure
import requests

from src.api.base_api import BaseApi


# todo 接口优化 亚宣


class Dept(BaseApi):
    def __init__(self, base_url):
        super().__init__(base_url)

    def users_list(self):
        '''
        获取指定部门下属员工列表
        https://ck-medium-api-test.cds8.cn/v1/dept/users?
        '''
        url = 'https://ck-medium-api-test.cds8.cn/v1/dept/users'
        params = {
            'is_all': 1,
            'classify': 1
        }
        # res = requests.get(url=url, params=params, headers=self.headers)

        json_res = self.send(method='get',path='dept/users',params=params)

        print()
        return json_res

    @allure.title('登录，获取token')
    def get_token(self, mobile='15055369706'):
        '''
        https://cmm-cas-test.cds8.cn/v2/cas/authorize
        post

        '''
        url = 'https://cmm-cas-test.cds8.cn/v2/cas/authorize'
        jsondata = {
            'mobile': mobile
        }
        data = {
            "grant_type": "code",
            "appId": 18888,
            "mobile": mobile,
            "code": "11",
            "device": "PC"
        }
        res = requests.post(url=url, json=data)
        res_json = res.json()
        print()
        return res_json

    @allure.step('获取当前用户列表')
    def get_user_info(self) -> int:
        url = 'https://ck-medium-api-test.cds8.cn/v1/user/info'

        # res = requests.get(url=url, headers=self.headers)
        json_res = self.send(method='get',path='user/info')
        print()
        return json_res


if __name__ == '__main__':
    res = Dept(base_url='https://ck-medium-api-test.cds8.cn/v1/').users_list()
    print()
    # Dept().get_user_info()
